//package com.liuguang.realgateway.filter;
//
//import com.liuguang.api.redis.RedisService;
//import com.liuguang.common.constans.CommonConstans;
//import com.liuguang.common.enums.CommonResultEnum;
//import com.liuguang.common.enums.RedisPreFixEnum;
//import com.liuguang.common.pojo.CommonResult;
//import com.liuguang.realgateway.utils.GatewayUtil;
//import org.apache.dubbo.config.annotation.DubboReference;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilter;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.handler.FilteringWebHandler;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//import org.springframework.util.StringUtils;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.util.Collections;
//import java.util.List;
//
///**
// * @ClassName: ValidateCodeFilter
// * @Description：验证码验证过滤器
// * @Author: wanghr
// * Date: 1:52 PM 2020/10/29
// * Version: 1.0
// */
//public class ValidateCodeFilter implements GatewayFilter {
//    private static final Logger logger = LoggerFactory.getLogger(ValidateCodeFilter.class);
//
//    private String VALIDATE_PATH = "/api/user/login";
//
//    @DubboReference
//    private RedisService redisService;
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        logger.info("进入ValidateCodeFilter");
//        ServerHttpRequest request = exchange.getRequest();
//        ServerHttpResponse response = exchange.getResponse();
//        String path = request.getURI().getPath();
//        // 不是登录接口不需要进行验证码验证
//        if (!org.apache.commons.lang3.StringUtils.equals(path, VALIDATE_PATH)) {
//            chain.filter(exchange);
//        }
//        String validateCode = request.getQueryParams().getFirst("validateCode");
//        if (!StringUtils.isEmpty(validateCode)) {
//            String username = request.getQueryParams().getFirst("username");
//            String key = RedisPreFixEnum.VERIFY_CODE_USERNAME_PASSWORD_TYPE.getValue() + request.getQueryParams().getFirst("codeKey");
////            String key = RedisPreFixEnum.VALIDATE_CODE.getValue() +username;
//            CommonResult<String> result = redisService.get(key);
//            if (CommonResultEnum.SUCCESS.getCode().equals(result.getCode())) {
//                if (org.apache.commons.lang3.StringUtils.equals(validateCode, result.getData())) {
//                    logger.info("验证码验证成功");
//                    chain.filter(exchange);
//                } else {
//                    return GatewayUtil.feedbackFriendly(response, "验证码匹配失败");
//                }
//            }
//            return GatewayUtil.feedbackFriendly(response, "获取缓存的验证码失败");
//        } else {
//            return GatewayUtil.feedbackFriendly(response, "验证码必填项不能为空");
//        }
//    }
//}
